package org.imaginedays.androidall.http;

import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.DefaultHttpClient;

public class HttpApiUtils {
	
	private String urlBuild(HashMap<String,String> parameters){
		
		Iterator iterator = parameters.entrySet().iterator();
		while (iterator.hasNext()) {
			Map.Entry<String, String> entry = (Entry<String, String>) iterator.next();
			String key = entry.getKey();
			String val = entry.getValue();
			
		}
		return null;
	}
	
	private void basicRequestExecution(String url){
		HttpClient httpClient = new DefaultHttpClient();
		HttpGet httpGet = new HttpGet(url);
		try {
			HttpResponse response = httpClient.execute(httpGet);
			HttpEntity entity = response.getEntity();
			if (entity!=null) {
				InputStream instream = entity.getContent();
				try{
					//TODO 
				}finally{
					instream.close();
				}
			}
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	private InputStream doHttpRequest(String url,HttpUriRequest request){
		try {
			URIBuilder builder = new URIBuilder(url);
		} catch (URISyntaxException e1) {
			e1.printStackTrace();
		}
		HttpClient httpClient = getClient();
		try {
			httpClient.execute(request);
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return null;
		
	}
	
	private HttpClient getClient(){
		return new DefaultHttpClient();
	}

}
